<!doctype html>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<html>
<head>
<meta charset="utf-8">

<jsp:include page="/common/commonCss.jsp"/>
<jsp:include page="/common/commonJs.jsp"/>
<link rel="stylesheet" type="text/css" href="${basePath }commonCss/css/global.css">
<link rel="stylesheet" type="text/css" href="${basePath }commonCss/css/layout.css">
<link rel="stylesheet" type="text/css" href="${basePath }commonCss/css/easyui.css">
<link rel="stylesheet" type="text/css" href="${basePath }commonCss/css/zTreeStyle.css">
<script src="${basePath }commonJs/jquery.min.js"></script>
<script src="${basePath }commonJs/jquery.easyui.min.js"></script>
<script src="${basePath }commonJs/jt_normal.js"></script>
<script src="${basePath }commonJs/jt_select.js"></script>
<script language="javascript" src="${basePath }commonJs/tags/My97DatePicker/WdatePicker.js"></script>
<script src="${basePath }commonJs/jquery.ztree.all.js"></script>

<script src="${basePath }commonJs/promotion/wolf_common.js"></script>
<script src="${basePath }commonJs/promotion/wolf_validation.js"></script>
<script type="text/javascript"
	src="${basePath}commonJs/ajaxfileupload.js"></script>

<title>嘉童游乐中心-商品信息</title>
</head>

	<SCRIPT type="text/javascript">
	 //标记被选中节点
	var setting = {
		check: {
			enable: true,
			chkboxType: { "Y": "ps", "N": "s" }/** { "Y": "ps", "N": "ps" }*/
		},
		data: {
			simpleData: {
				enable: true
			}
		}
	};

	$(document).ready(function(){
		defualtZtree();
		
		/**联系方式*/
		var $numInfo=document.getElementById('num_info'),
		$num=document.getElementById('phone'),
		_val,_val1,_val2;
	$num.onkeyup=function(){
		var val=this.value=this.value.replace(/[^\d]/g,''),
			len=val.length;	
		if(len > 15){
			p = false;
			return;
		}else{
			p = true;
		}
		p = true; 
		if(val!=''){$numInfo.style.display='block';}
		if(len<=3){
			_val=_val1= val.substr(0,3);
		}
		else if(len>3&&len<=7){
			_val1 =val.substr(0,3);
			_val=_val2=_val1+"-"+val.substr(3,len);
		}
		else if(len>7){
			_val2 =val.substr(0,3)+"-"+val.substr(3,4);
			_val=_val2+'-'+val.substr(7,len);
		}
		$numInfo.innerHTML=_val;
	}
	$num.onblur=function(){
		$numInfo.style.display='none';		
	}
	});
	
	function defualtZtree(){
		$.ajax({ 
			url: "${basePath }authority/role/seacheByPidSecObj.shtml",
			data:"pid=",
			dataType: 'json',
			type:'POST',
			success: function(data){
				if(wolf.isNotNull(data)){
					$.fn.zTree.init($("#sptree"), setting, data);
				}
	      	},
	      	error:function(data){
	      		alert(data);
	      	}
		});
	}
	
	/**
		获取所有选中节点
	*/
	function getZtreeCheckNodes(){
		var checkNode = "";
		var treeObj = $.fn.zTree.getZTreeObj("sptree");
		var nodes = treeObj.getCheckedNodes(true);
		if(wolf.isNotNull(nodes)){
			wolf.data_foreach(nodes, function(i,node){
				var nodeObj = "&objList["+i+"].fkObjId="+node.id;
				var s = node.getCheckStatus();
				if(s.half == true && s.checked == true){
					nodeObj += "&objList["+i+"].chkStat="+1;
				}else{
					nodeObj += "&objList["+i+"].chkStat="+0;
				}
				checkNode += nodeObj;
			});
		}
		return checkNode;
	}
	/**验证表单数据*/
	function isValidation(){
		wolf_v.v_bean.formId="user_add_form";
		wolf_v.v_bean.alertType="5";
		wolf_v.v_bean.alertTypeCall=v_msg;
		wolf_v.v_validation();
		checkFlag = wolf_v.v_check_result;
		if(checkFlag){
			isCheckZKPass();
		}
	}
	function v_msg(t,arry){
		if(t == -1){
			if(wolf.isNotNull( arry ) && arry.length > 0){
				var obj = arry[arry.length - 1];
				alertInfo(obj.t.replace("&p",obj.d));
			}
		}
	}
	var checkFlag = true;
	/**提交数据*/
	function form_submit(){
		isValidation();
		if(checkFlag && isPhone()){
			$.ajax({ 
				url: "${basePath}authority/user/addUser.shtml",
				data:$("#user_add_form").serialize() + getZtreeCheckNodes(),
				dataType: 'json',
				type:'POST',
				success: function(data){
					window.location.href="${basePath}authority/user/home.shtml";
				}
			});
		}
	}
	/**验证登录账号*/
	function isCheckLoginId(){
		var loginId = $("#_loginId").val();
		$.ajax({ 
			url: "${basePath}authority/user/seacheByUser.shtml",
			data:"loginId="+loginId,
			dataType: 'json',
			type:'POST',
			success: function(data){
				if(wolf.isNotNull(data)){
					checkFlag = false; 
					$("#_loginId").val("");
					alertInfo("登录账号已经重,请换一个试试！");
				}else{
					checkFlag = true; 
				}
			}
		});
	}
	/**验证登录账号*/
	function isCheckZKPass(){
		var radioCheck =$('input[name="discountEna"]:checked').val();
		if(radioCheck != 0){
			var pass = $("#_discountPwd").val();
			var pass1 = $("#_discountPwds").val();
			if(wolf.isNull(pass) || wolf.isNull(pass)){
				alertInfo("打折密码或确认密码不能为空！");
				checkFlag = false; 
			}else if(pass != pass1){
				alertInfo("打折密码与确认密码不同,请从新输入！");
				checkFlag = false; 
			}
		}
	}
	function dzmm(t){
		
		if(t == 0){
			$('#d1mm').hide();
			$('#d2mm').hide();
			
		}else{
			$('#d1mm').show();
			$('#d2mm').show();
		}
		$('#_discountPwd').val("");
		$('#_discountPwds').val("");
	}
	
	function upload() {
		if ($("#ui-upload-input").val() == '') {
			alertError("请选择上传文件！");
			return false;
		}
		$.ajaxFileUpload({
			url : '${basePath}authority/user/uploadFile.shtml',
			secureuri : false,
			fileElementId : 'ui-upload-input',
			dataType : 'text',
			success : function(data) {
				data = decodeURI(data);
				if (data != "") {
					$("#imagePath").val(data);
					alertInfo("文件上传成功！");
					$("#ui-upload-filepathtxt").val("");
				} else {
					alertError("上传失败，请重试！");
					$("#ui-upload-filepathtxt").val("");
				}
			},
			error : function(XMLHttpRequest) {
				 ajaxError(XMLHttpRequest);
				}
		});
	}

	function fileName() {
		var fileName = $("#ui-upload-input").val();
		if (fileName.lastIndexOf("\\") != -1) {
			fileName = fileName.substring(fileName.lastIndexOf("\\") + 1);
		}
		$("#ui-upload-filepathtxt").val(fileName);
	}
	/* 
	window.onload=function(){
		
	} */
	var p = true;
	function isPhone(){
		if(!p){
			alertInfo("联系电话长度最大不能超过15位！");
			return false;
		}
		return p;
	}
	</SCRIPT>
<title>嘉童游乐中心-库存调整</title>
</head>
<body class="bg">
<div class="content m_auto">
	<div class="content_l mt10">
    	<ul>
    	<shiro:hasPermission name="authority/role/home.shtml">
         <li><a href="${basePath}authority/role/home.shtml"><i class="nav_icon_u"></i><br>角色管理</a></li>
           </shiro:hasPermission>
           <shiro:hasPermission name="authority/user/home.shtml">
            <li class="content_hover"><a href="${basePath}authority/user/home.shtml"><i class="nav_icon_t"></i><br>用户管理</a></li>
           </shiro:hasPermission>
           <shiro:hasPermission name="SalesRelation/mem.shtml">
            <li><a href="${basePath}SalesRelation/mem.shtml"><i class="nav_icon_s"></i><br>销售关联会员</a></li>
            </shiro:hasPermission>
            <shiro:hasPermission name="ParRoomDetail/ParRoom.shtml">
            <li ><a href="${basePath}ParRoomDetail/ParRoom.shtml"><i class="nav_icon_r"></i><br>房间管理</a></li>
           </shiro:hasPermission>
           <shiro:hasPermission name="SysBarCode/system.shtml">
            <li><a href="${basePath }SysBarCode/system.shtml"><i class="nav_icon_q"></i><br>条码维护</a></li>
            </shiro:hasPermission>
            <shiro:hasPermission name="WfmAuthorize/toShenP.shtml">
            <li><a href="${basePath}WfmAuthorize/toShenP.shtml"><i class="nav_icon_s"></i><br>审批转授权</a></li>
            </shiro:hasPermission>
            <shiro:hasPermission name="holiday/sysHoliday.shtml">
            <li><a href="${basePath}holiday/sysHoliday.shtml"><i class="nav_icon_q"></i><br>节假日管理</a></li>
            </shiro:hasPermission>
        </ul>
    </div>
    <div class="content_r mt10">
    	<!---- 内容 --->
    	<form action="${basePath }/authority/user/addUser.shtml" id="user_add_form">
        <div class="file_single_dl_x fixed mt20">
        	<dl class="fixed">
            	<dd><label>所属门店：</label>
                	<!----select--->
                    <div class="uboxstyle">
                        <select name="fkBranId" id="fkBranId">
                        	
                        		<c:forEach items="${branAll }" var="bran" varStatus="cc">
	                            	<c:choose>
	                            		<c:when test="${branId == 'ZB' }">
	                            			<c:if test="${bran.pkBranId !='ZB'}">
	                            				<option value="${bran.pkBranId}">${bran.branName }</option>
	                            			</c:if>
	                            			<c:if test="${bran.pkBranId =='ZB'}">
	                            					<option value="${bran.pkBranId}">${bran.branName }</option>
	                            			</c:if>
		                            	</c:when>
		                            	<c:when test="${branId != 'ZB' && branId ==bran.pkBranId }">
		                            		
		                            		<option value="${bran.pkBranId}">${bran.branName }</option>
		                            	</c:when>
		                            	
                            		</c:choose>
	                            </c:forEach>
	                            
                        	
	                        </select>
                    </div>
                    <!----select--->
                    <span class="color_red ml5">*</span>
                </dd>
                <dd><label>用户姓名：</label><input type="text" class="iput_t w200" value="" name="usrName" data_v="not_empty" data_v_info="用户姓名"><span class="color_red ml5">*</span></dd>
                <dd><label>登录账号：</label><input type="text" class="iput_t w200"  value="" name="loginId" id="_loginId" onblur="isCheckLoginId()" data_v="not_empty" data_v_info="登录账号"><span class="color_red ml5">*</span></dd>
                <dd><label>邮箱：</label><input type="text" class="iput_t w200"  value="" name="email" data_v="email" data_v_info="邮箱"><span class="color_red ml5">*</span></dd>
                <dd><label>联系电话：</label>
                
	                <!-- <input type="text" class="iput_t w200"  value="" name="phone" data_v="phone" data_v_info="联系电话">
	                <span class="color_red ml5">*</span> -->
                	<div class="formx fl">
                      <span id="num_info" for="conMobile"></span>
                      <input type="text" id="phone" class="iput_t w200"  value="" name="phone"  data_v="not_empty" data_v_info="联系电话">
                    </div>
               		<span class="color_red ml5">*</span>
                </dd>
                  <dd><input type="hidden" name="imagePath" id="imagePath"></dd>
                <dd><label>职务级别：</label>
                
                	<!----select--->
                    <div class="uboxstyle">
                        <select name="jobLvl" id="jobLvl">
                            <option value="1">1级</option>
                            <option value="2">2级</option>
                            <option value="3">3级</option>
                            <option value="4">4级</option>
                        </select>
                    </div>
                    <input type="hidden" name="pwdFlag" value="1">
                    <!----select--->
                    <span class="color_red ml5">*</span>
                </dd>
                <dd class="w360"><label>用户角色：</label>
                	<ul class="fl younh_x_ul ">
                		<c:forEach items="${roleAll }" var="role">
                         	<li><input type="checkbox" class="mr5" name="roleList" value="${role.pkRoleId }">${role.roleName }</li>
                         </c:forEach>
                    </ul>
                </dd>
                <dd class="w630"><label>用户权限：</label>
                	<div class="ztree ztree_y fl" id="sptree"></div>
                </dd>
                <dd class="w630"><label>头像：</label>
                <div style="width:260px !important" class="upload_box fl">	
                    <span id="ui-upload-holder fr">
                   <input type="text" class="iput_t fl w200" name="fkAgmFile"  id="ui-upload-filepathtxt">
                    <input type="button" id="ui-upload-txt" value="浏览" class="btn_l ml10">
				<span id="ui-upload-holder fr"> <input type="file"
					id="ui-upload-input" name="file" onchange="fileName()">
				</span>
                    </span>
                </div>
                <input type="button" value="上传" class="btn_l ml10 fl" onclick="upload()">
            </dd>
            </dl>
            
            <dl class="w360 fixed">
                <dd class="w360"><label>特殊折扣：</label>
                	<ul class="fl ul_radio">
                    	<li><input type="radio" class="mr5" name="discountEna" value="0" onclick="javascript:dzmm(0)" checked="checked">不允许</li>
                        <li><input type="radio" class="mr5" name="discountEna" value="1"  onclick="javascript:dzmm(1)">允许</li>
                    </ul>
                </dd>
                <dd id="d1mm" style="display: none;"><label>折扣密码：</label><input type="password" class="iput_t w200" id="_discountPwd" name="discountPwd" value=""  ></dd>
                <dd id="d2mm" style="display: none;"><label>确认密码：</label><input type="password" class="iput_t w200" id="_discountPwds" name="discountPwds" value=""  onblur="isCheckZKPass()" ></dd>
            </dl>
        </div>
        
        <!----底部按钮----->
        <div class="btm_btn mt10">
                <dl>
                    <!-- <dd><input type="button" class="btn" value="修改密码" onclick="$('#q').window('open')"></dd>
                    
                     -->
                     
                    <dd><input type="button" class="btn" value="保存" onclick="form_submit()"></dd>
                     <dd><input type="button" class="btn" value="返回" onclick="window.location.href='${basePath}authority/user/home.shtml'"></dd>
                </dl>
        </div>
        </form>
        <!----底部按钮----->
        <!---- 内容 --->
    </div>
</div>
